package com.ruoyi.web.controller.lqm;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lqm.domain.LqmMaterial;
import com.ruoyi.lqm.service.ILqmMaterialService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物料清单Controller
 * 
 * @author dell
 * @date 2019-10-12
 */
@Controller
@RequestMapping("/lqm/material")
public class LqmMaterialController extends BaseController
{
    private String prefix = "lqm/material";

    @Autowired
    private ILqmMaterialService lqmMaterialService;

    @RequiresPermissions("lqm:material:view")
    @GetMapping()
    public String material()
    {
        return prefix + "/material";
    }

    /**
     * 查询物料清单列表
     */
    @RequiresPermissions("lqm:material:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LqmMaterial lqmMaterial)
    {
        startPage();
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        return getDataTable(list);
    }

    /**
     * 导出物料清单列表
     */
    @RequiresPermissions("lqm:material:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LqmMaterial lqmMaterial)
    {
        List<LqmMaterial> list = lqmMaterialService.selectLqmMaterialList(lqmMaterial);
        ExcelUtil<LqmMaterial> util = new ExcelUtil<LqmMaterial>(LqmMaterial.class);
        return util.exportExcel(list, "material");
    }

    /**
     * 新增物料清单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存物料清单
     */
    @RequiresPermissions("lqm:material:add")
    @Log(title = "物料清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LqmMaterial lqmMaterial)
    {
        return toAjax(lqmMaterialService.insertLqmMaterial(lqmMaterial));
    }

    /**
     * 修改物料清单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        LqmMaterial lqmMaterial = lqmMaterialService.selectLqmMaterialById(id);
        mmap.put("lqmMaterial", lqmMaterial);
        return prefix + "/edit";
    }

    /**
     * 修改保存物料清单
     */
    @RequiresPermissions("lqm:material:edit")
    @Log(title = "物料清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LqmMaterial lqmMaterial)
    {
        return toAjax(lqmMaterialService.updateLqmMaterial(lqmMaterial));
    }

    /**
     * 删除物料清单
     */
    @RequiresPermissions("lqm:material:remove")
    @Log(title = "物料清单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lqmMaterialService.deleteLqmMaterialByIds(ids));
    }
}
